package cn.iocoder.yudao.module.liveprice.service.price;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 价格缓存服务
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PriceCacheService {

    private final RedisTemplate<String, Object> redisTemplate;
    private static final String PRICE_CACHE_KEY_PREFIX = "price:";

    /**
     * 更新价格缓存
     *
     * @param id       价格ID
     * @param priceObj 价格对象
     */
    public void updatePrice(String id, Object priceObj) {
        String cacheKey = PRICE_CACHE_KEY_PREFIX + id;
        redisTemplate.opsForValue().set(cacheKey, priceObj);
        log.debug("更新价格缓存: {}", id);
    }

    /**
     * 获取价格
     *
     * @param id 价格ID
     * @return 价格对象
     */
    public Object getPrice(String id) {
        String cacheKey = PRICE_CACHE_KEY_PREFIX + id;
        return redisTemplate.opsForValue().get(cacheKey);
    }

    /**
     * 删除价格缓存
     *
     * @param id 价格ID
     */
    public void deletePrice(String id) {
        String cacheKey = PRICE_CACHE_KEY_PREFIX + id;
        redisTemplate.delete(cacheKey);
        log.debug("删除价格缓存: {}", id);
    }
} 